package L01;
//进程终止，该方法可能不够及时
public class T08 {

    //将isQuit放在main函数中作为一个局部变量
    //lambda表达式自动捕获的变量只能是final或者实际上是final(捕获后不再对值进行修改)
    //内部类访问外部类，没有final的限制
    private static boolean isQuit=false;

    public static void main (String[] args) throws InterruptedException {
        Thread t=new Thread (()->{
            while(!isQuit){
                System.out.println ("线程工作中");
                try {
                    Thread.sleep (1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException (e);
                }
            }
            System.out.println ("线程工作完毕");
        });

        t.start ();
        Thread.sleep (2000);

        isQuit=true;
        System.out.println ("设置isQuit为true");

    }
}
